package com.example.demo.controller;

import com.example.demo.result.Result;
import com.example.demo.service.SessionService;
import com.example.demo.vo.sessionVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/session")
@Tag(name="会话相关接口")
public class SessionController {

    final SessionService sessionService;

    /**
     * 获取对话列表
     * @param userId
     * @return
     */
    @Operation(summary = "获取用户会话列表接口")
    @GetMapping("/list")
    public Result<List<sessionVO>> getList(@RequestParam("userId")Long userId){
        List<sessionVO> list=sessionService.getList(userId);
        return Result.success(list);
    }


    /**
     * 返回会话id
     * @return
     */
    @Operation(summary = "获取会话id接口")
    @PostMapping("/create")
    public Result<Long> createSession(@RequestParam("mode")Long mode){
        return Result.success(sessionService.createSession(mode));
    }

    /**
     * 根据角色ID获取或创建会话
     * @param roleId 角色ID
     * @return 会话ID
     */
    @Operation(summary = "根据角色ID获取或创建会话接口")
    @GetMapping("/role/{roleId}")
    public Result<Long> getOrCreateSessionByRoleId(@PathVariable Long roleId){
        return Result.success(sessionService.getOrCreateSessionByRoleId(roleId));
    }
}
